<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=7.4.0">
  <link rel="mask-icon" href="/images/avatar.svg?v=7.4.0" color="#222">
  <link rel="alternate" href="/atom.xml" title="Anemone's Blog" type="application/atom+xml">
  <meta name="google-site-verification" content="Re5JdegRYzNFco-rC9lYIsvSWIgh5JvyfhuEaZCeFCk">
  <meta name="baidu-site-verification" content="opTC8YN3Pn">

<link rel="stylesheet" href="/css/main.css?v=7.4.0">


<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="Infer作为facebook 开源的使用 ocaml 开发静态代码检测工具，作为公司的产品调研对象，本文就其使用和原理两方面进行分析。GitHub：https://github.com/facebook/infer教程：https://infer.liaohuqiu.net/">
<meta name="keywords" content="源码安全,C&#x2F;C++,Infer">
<meta property="og:type" content="article">
<meta property="og:title" content="Infer试用以及扫描原理分析">
<meta property="og:url" content="http://anemone.top/whitebox-infer/index.html">
<meta property="og:site_name" content="Anemone&#39;s Blog">
<meta property="og:description" content="Infer作为facebook 开源的使用 ocaml 开发静态代码检测工具，作为公司的产品调研对象，本文就其使用和原理两方面进行分析。GitHub：https://github.com/facebook/infer教程：https://infer.liaohuqiu.net/">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://anemone.top/whitebox-infer/1566373102585.png">
<meta property="og:image" content="http://anemone.top/whitebox-infer/1566370930925.png">
<meta property="og:image" content="http://anemone.top/whitebox-infer/SepSplit.jpg">
<meta property="og:updated_time" content="2019-09-22T10:14:18.706Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Infer试用以及扫描原理分析">
<meta name="twitter:description" content="Infer作为facebook 开源的使用 ocaml 开发静态代码检测工具，作为公司的产品调研对象，本文就其使用和原理两方面进行分析。GitHub：https://github.com/facebook/infer教程：https://infer.liaohuqiu.net/">
<meta name="twitter:image" content="http://anemone.top/whitebox-infer/1566373102585.png">
  <link rel="canonical" href="http://anemone.top/whitebox-infer/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>Infer试用以及扫描原理分析 | Anemone's Blog</title>
  








  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Anemone's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-about">
      
    

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="fa fa-search fa-fw"></i>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="http://anemone.top/whitebox-infer/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Anemone">
      <meta itemprop="description" content="关注Web安全、移动安全、Fuzz测试和机器学习">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Anemone's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">Infer试用以及扫描原理分析

          
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-24 09:27:49" itemprop="dateCreated datePublished" datetime="2019-08-24T09:27:49+08:00">2019-08-24</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-09-22 18:14:18" itemprop="dateModified" datetime="2019-09-22T18:14:18+08:00">2019-09-22</time>
              </span>
            
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/源码安全/" itemprop="url" rel="index"><span itemprop="name">源码安全</span></a></span>

                
                
              
            </span>
          

          
            <span id="/whitebox-infer/" class="post-meta-item leancloud_visitors" data-flag-title="Infer试用以及扫描原理分析" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>Infer作为facebook 开源的使用 ocaml 开发静态代码检测工具，作为公司的产品调研对象，本文就其使用和原理两方面进行分析。</p><p>GitHub：<a href="https://github.com/facebook/infer" target="_blank" rel="noopener">https://github.com/facebook/infer</a></p><p>教程：<a href="https://infer.liaohuqiu.net/" target="_blank" rel="noopener">https://infer.liaohuqiu.net/</a></p><a id="more"></a>


<h1 id="Usage"><a href="#Usage" class="headerlink" title="Usage"></a>Usage</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Gradle</span></span><br><span class="line">infer -- gradle &lt;gradle task, e.g. <span class="string">"build"</span>&gt;</span><br><span class="line">infer -- ./gradlew &lt;gradle task, e.g. <span class="string">"build"</span>&gt;</span><br><span class="line"><span class="comment"># Maven</span></span><br><span class="line">infer -- mvn &lt;maven target&gt;</span><br></pre></td></tr></table></figure>
<h1 id="检测能力"><a href="#检测能力" class="headerlink" title="检测能力"></a>检测能力</h1><p>官网上看到能够检测到的问题有：</p>
<p>Java：</p>
<ul>
<li>Resource Leak</li>
<li>Null dereference</li>
</ul>
<p>C and Objective-C</p>
<ul>
<li>Resource leak</li>
<li>Memory leak</li>
<li>Null dereference</li>
<li>Parameter not null checked</li>
<li>Ivar not null checked</li>
<li>Premature nil termination argument</li>
</ul>
<p>Bugs reported only in Objective-C</p>
<ul>
<li>Retain cycle</li>
</ul>
<p>参见：<a href="https://infer.liaohuqiu.net/docs/infer-bug-types.html" target="_blank" rel="noopener">https://infer.liaohuqiu.net/docs/infer-bug-types.html</a></p>
<p>但是定位到源代码：<a href="https://github.com/facebook/whitebox-infer/blob/master/whitebox-infer/src/base/IssueType.ml后，发现其还能检测其存在注入类型的漏洞，不知为何没有扫描到。" target="_blank" rel="noopener">https://github.com/facebook/whitebox-infer/blob/master/whitebox-infer/src/base/IssueType.ml后，发现其还能检测其存在注入类型的漏洞，不知为何没有扫描到。</a></p>
<h1 id="试用"><a href="#试用" class="headerlink" title="试用"></a>试用</h1><p>Webgoat检测到16个问题，14个空引用和2个资源泄露：</p>
<p><img src="/whitebox-infer/1566373102585.png" alt="1566373102585"></p>
<p>扫描InsecureBankv2:</p>
<p><img src="/whitebox-infer/1566370930925.png" alt="1566370930925"></p>
<h1 id="优势"><a href="#优势" class="headerlink" title="优势"></a>优势</h1><ul>
<li><p>增量分析</p>
</li>
<li><p>能够分析大规模程序</p>
</li>
</ul>
<h1 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h1><p><a href="https://infer.liaohuqiu.net/docs/separation-logic-and-bi-abduction.html" target="_blank" rel="noopener">分离逻辑（separation logic）和双向假说推理（bi-abduction）</a>，<a href="https://en.wikipedia.org/wiki/Hoare_logic" target="_blank" rel="noopener">霍尔逻辑</a>和<a href="https://en.wikipedia.org/wiki/Abstract_interpretation" target="_blank" rel="noopener">抽象解释</a>，分离逻辑用来检测bug，双向假说推理用来做增量分析。</p>
<h2 id="分离逻辑"><a href="#分离逻辑" class="headerlink" title="分离逻辑"></a>分离逻辑</h2><p>一开始用于内存管理的逻辑</p>
<script type="math/tex; mode=display">
x\mapsto y * y\mapsto x</script><p>$x \mapsto y$ 指指针x指向值y（x points to y），$A*B$指A和B处于分离的两块内存中（and separately），因此以上公式被叫做（x 指向y，同时y指向x），可以用下图表示：</p>
<p><img src="/whitebox-infer/SepSplit.jpg" alt="static/images/SepSplit.jpg"></p>
<p>接着使用Hoare三元组$\{pre\}prog\{post\}$，表示程序行为，$pre$指前置条件，$prog$指程序片段$post$为后置条件。例如使用Hoare三元组描述一个关闭资源的函数：</p>
<script type="math/tex; mode=display">
\{r\mapsto open\}closeResource(r)\{r\mapsto closed\}(spec)</script><p>它说明，一个正确的关闭资源的函数运行前，r资源应该是打开的，运行后r资源应该是关闭的，如果不符合则代码有问题。</p>
<p>那么若有两个资源$r_1$和$r_2$仅关闭$r_1$可以表示成：</p>
<script type="math/tex; mode=display">
\{r_1\mapsto open * r_2\mapsto open\}closeResource(r_1)\{r_1\mapsto closed * r_2\mapsto open\}(use)</script><p>这里使用了一个小规范（spec）去更新了一个大规范（use），更一般的，我们有：</p>
<script type="math/tex; mode=display">
\{pre\}prog\{post\}\rightarrow\{pre*frame\}prog\{post*frame\}</script><p>这一规则也被称为逻辑分离中的frame规则，$frame$描述了不变的状态，属于来自于就像动画场景中背景（frame）——动画场景中背景不会变。</p>
<p>这一规则用于数学推理，它揭示了逻辑推理应该聚焦于程序访问资源的那一块逻辑，并且分离的两块可以独立分析。</p>
<h2 id="双向假说推理"><a href="#双向假说推理" class="headerlink" title="双向假说推理"></a>双向假说推理</h2><p>A推出B表示为：</p>
<script type="math/tex; mode=display">
A \vdash B</script><p>在传统逻辑推理中，一个推理问题被定义为：</p>
<ul>
<li><p>给定假设A和目标G</p>
</li>
<li><p>找到一个M，使如下公式成立：</p>
<script type="math/tex; mode=display">
A \land M \vdash G</script></li>
</ul>
<p>应用到分离逻辑问题，即：</p>
<script type="math/tex; mode=display">
A * M \vdash G</script><p>双向假说推理将问题拓展成：</p>
<script type="math/tex; mode=display">
A*?antiframe \vdash G*?frame</script><p>即infer需要找到一对$antiframe$和$frame$让上式成立。</p>
<p>这在做增量扫描是很重要。</p>
<p>为了说明问题，例如我们有如下函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">lst_nd* <span class="title">q</span><span class="params">(lst_nd *y)</span> </span>&#123; <span class="comment">// Inferred Pre: list(y) </span></span><br><span class="line">    lst_nd *x, *z;</span><br><span class="line">    x=<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(lst_nd)); x-&gt;tail=<span class="number">0</span>;</span><br><span class="line">    z=<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(lst_nd)); z-&gt;tail=<span class="number">0</span>; <span class="comment">// Abducted: list(y), Framed: z|-&gt;0 </span></span><br><span class="line">    merge(x,y); <span class="comment">// Obtained Post: list(x)*z|-&gt;0 </span></span><br><span class="line">    merge(x,z); <span class="comment">// Obtained Post: list(x) </span></span><br><span class="line">    <span class="keyword">return</span>(x);</span><br><span class="line">&#125; <span class="comment">// Inferred Post: list(ret)</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">merge</span><span class="params">(lst_nd *x,lst_nd *y)</span></span>&#123;<span class="comment">//SUMMARY ONLY </span></span><br><span class="line">    <span class="comment">// Given Pre: list(x) * list(y)</span></span><br><span class="line">    <span class="comment">// x=x+y</span></span><br><span class="line">&#125; <span class="comment">// Given Post: list(x)</span></span><br></pre></td></tr></table></figure>
<p>要分析merge有没有空指针，有</p>
<script type="math/tex; mode=display">
\{x\mapsto list * y\mapsto list\}merge(x,y)\{x\mapsto list\}</script><p>如果开始分析q到第5行，我们有：</p>
<script type="math/tex; mode=display">
A=x\mapsto 0 *z \mapsto 0</script><p>但是我们的前提条件是$G=x\mapsto list * y\mapsto list$那么开始推导：</p>
<script type="math/tex; mode=display">
x\mapsto0 *z \mapsto 0 * ?antiframe \vdash x\mapsto list * y \mapsto list * ?frame</script><p>因此 $antiframe=y\mapsto list$且$frame=z\mapsto 0$，这说明，如果想要分析q()函数有没有空指针，那么我们现在只需要分析$y\mapsto list$是成立就行了。</p>
<p><strong>这意味着，如果将来发新版本，若q()函数不变，则不需要再分析该函数，只需要分析改变的那些函数有没有改变$y \mapsto list$即可。</strong></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>Infer目前的检测能力只局限于空指针和数据泄露问题，然而在检测项中发现了更多，怀疑是开源的是缩水的版本，而其增量分析的思想值得扫描器借鉴，其可用来完成commit级别的SAST和Serveless的安全检测。</p>

    </div>

    
    
    
        
      
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Anemone</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://anemone.top/whitebox-infer/" title="Infer试用以及扫描原理分析">http://anemone.top/whitebox-infer/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>
</div>

      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/源码安全/" rel="tag"># 源码安全</a>
            
              <a href="/tags/C-C/" rel="tag"># C/C++</a>
            
              <a href="/tags/Infer/" rel="tag"># Infer</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/crypto-PaddingOracle攻击/" rel="next" title="PaddingOracle攻击">
                  <i class="fa fa-chevron-left"></i> PaddingOracle攻击
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/deserialize-AutoFindPOP/" rel="prev" title="Automated Discovery of Deserialization Gadget Chain解读">
                  Automated Discovery of Deserialization Gadget Chain解读 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          
    
    <div class="comments" id="gitalk-container"></div>
  

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Usage"><span class="nav-number">1.</span> <span class="nav-text">Usage</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#检测能力"><span class="nav-number">2.</span> <span class="nav-text">检测能力</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#试用"><span class="nav-number">3.</span> <span class="nav-text">试用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#优势"><span class="nav-number">4.</span> <span class="nav-text">优势</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#原理"><span class="nav-number">5.</span> <span class="nav-text">原理</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#分离逻辑"><span class="nav-number">5.1.</span> <span class="nav-text">分离逻辑</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#双向假说推理"><span class="nav-number">5.2.</span> <span class="nav-text">双向假说推理</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/avatar.jpg"
      alt="Anemone">
  <p class="site-author-name" itemprop="name">Anemone</p>
  <div class="site-description" itemprop="description">关注Web安全、移动安全、Fuzz测试和机器学习</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">52</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        <span class="site-state-item-count">29</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        <span class="site-state-item-count">71</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
</div>
  <div class="feed-link motion-element">
    <a href="/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/anemone95" title="GitHub &rarr; https://github.com/anemone95" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:anemone95@qq.com" title="E-Mail &rarr; mailto:anemone95@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
  </div>
  <div class="cc-license motion-element" itemprop="license">
    
  
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">anemone</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.4.0</div>

        






  
  <script>
  function leancloudSelector(url) {
    return document.getElementById(url).querySelector('.leancloud-visitors-count');
  }
  if (CONFIG.page.isPost) {
    function addCount(Counter) {
      var visitors = document.querySelector('.leancloud_visitors');
      var url = visitors.getAttribute('id').trim();
      var title = visitors.getAttribute('data-flag-title').trim();

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length > 0) {
            var counter = results[0];
            Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
              .then(response => response.json())
              .then(() => {
                leancloudSelector(url).innerText = counter.time + 1;
              })
            
              .catch(error => {
                console.log('Failed to save visitor count', error);
              })
          } else {
              Counter('post', '/classes/Counter', { title: title, url: url, time: 1 })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.log('Failed to create', error);
                });
            
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  } else {
    function showTime(Counter) {
      var visitors = document.querySelectorAll('.leancloud_visitors');
      var entries = [...visitors].map(element => {
        return element.getAttribute('id').trim();
      });

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length === 0) {
            document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
              element.innerText = 0;
            });
            return;
          }
          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.url;
            var time = item.time;
            leancloudSelector(url).innerText = time;
          }
          for (var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = leancloudSelector(url);
            if (element.innerText == '') {
              element.innerText = 0;
            }
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  }

  fetch('https://app-router.leancloud.cn/2/route?appId=o5UaCJdPfEG0g7MVxXSMagpT-gzGzoHsz')
    .then(response => response.json())
    .then(({ api_server }) => {
      var Counter = (method, url, data) => {
        return fetch(`https://${api_server}/1.1${url}`, {
          method: method,
          headers: {
            'X-LC-Id': 'o5UaCJdPfEG0g7MVxXSMagpT-gzGzoHsz',
            'X-LC-Key': 'c6IN1PuMV3QPltJcrHfn74Gt',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      if (CONFIG.page.isPost) {
        const localhost = /http:\/\/(localhost|127.0.0.1|0.0.0.0)/;
        if (localhost.test(document.URL)) return;
        addCount(Counter);
      } else if (document.querySelectorAll('.post-title-link').length >= 1) {
        showTime(Counter);
      }
    });
  </script>






        
      </div>
    </footer>
  </div>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script>
  <script src="https://cdn.bootcss.com/velocity/1.2.1/velocity.min.js"></script>
  <script src="https://cdn.bootcss.com/velocity/1.2.1/velocity.ui.js"></script>
<script src="/js/utils.js?v=7.4.0"></script><script src="/js/motion.js?v=7.4.0"></script>
<script src="/js/schemes/pisces.js?v=7.4.0"></script>
<script src="/js/next-boot.js?v=7.4.0"></script>



  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>








  <script src="/js/local-search.js?v=7.4.0"></script>










<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.bootcss.com/mermaid/8.2.6/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'forest',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>




  

  
    
      
<script type="text/x-mathjax-config">

  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$', '$'], ['\\(', '\\)'] ],
      processEscapes: true,
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      equationNumbers: {
        autoNumber: 'AMS'
      }
    }
  });

  MathJax.Hub.Register.StartupHook('TeX Jax Ready', function() {
    MathJax.InputJax.TeX.prefilterHooks.Add(function(data) {
      if (data.display) {
        var next = data.script.nextSibling;
        while (next && next.nodeName.toLowerCase() === '#text') {
          next = next.nextSibling;
        }
        if (next && next.nodeName.toLowerCase() === 'br') {
          next.parentNode.removeChild(next);
        }
      }
    });
  });

  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for (i = 0; i < all.length; i += 1) {
      element = document.getElementById(all[i].inputID + '-Frame').parentNode;
      if (element.nodeName.toLowerCase() == 'li') {
        element = element.parentNode;
      }
      element.classList.add('has-jax');
    }
  });
</script>
<script>
  NexT.utils.getScript('//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML', () => {
    MathJax.Hub.Typeset();
  }, window.MathJax);
</script>

    
  

  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID: 'f3075553d7b0225df6ca',
      clientSecret: '68362ba87c4cc8e13103afcf729f5bd8ea176a78',
      repo: 'anemone95.github.io',
      owner: 'Anemone95',
      admin: ['Anemone95'],
      id: '63692e8ee4115bacef092ff39f6d7080',
        language: window.navigator.language || window.navigator.userLanguage,
      
      distractionFreeMode: 'true'
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
</script>

</body>
</html>
